from email.helper import *
from django import template

def number_format(num, places=2):
   language_code = get_language()

   places = max(0,places)
   tmp = "%.*f" % (places, num)

   if language_code=='en':
       dec = '.'
       group = ','
   else:
       dec = ','
       group = '.'
       
   tmp = tmp.replace('.',dec)
   point = tmp.find(dec)
   integer = (point == -1) and tmp or tmp[:point]
   decimal = (point != -1) and tmp[point:] or ""
   
   count =  0
   formatted = []
   for i in range(len(integer), 0, -1):
       count += 1
       formatted.append(integer[i - 1])
       if count % 3 == 0 and i - 1:
           formatted.append(group)

   integer = "".join(formatted[::-1])
   return integer+decimal 